package org.rain.core.querygen;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.rain.core.querygen.token.Token;
import org.springframework.core.Ordered;

/**
 * created by yangtong on 2025/4/6 下午10:30
 * <p>
 * 查询条件
 */
public abstract class AbsQueryCondition implements Ordered {

    /**
     * 判断某个参数是否可以匹配上这个查询条件
     *
     * @param token 分词token
     */
    public abstract Boolean isMatch(Token token);

    /**
     * 根据条件组装QueryWrapper
     */
    public abstract <T> QueryWrapper<T> genQueryWrapper(QueryWrapper<T> queryWrapper, Token token);

    /**
     * 判断是否为逆向条件
     */
    protected <T> QueryWrapper<T> positiveOrNegate(QueryWrapper<T> queryWrapper, Token token) {
        if (token.isPositive()) {
            return positive(queryWrapper, token);
        } else {
            return negate(queryWrapper, token);
        }
    }

    protected abstract <T> QueryWrapper<T> positive(QueryWrapper<T> queryWrapper, Token token);

    protected abstract <T> QueryWrapper<T> negate(QueryWrapper<T> queryWrapper, Token token);
}
